package com.atguigu.exer;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * @author yihu
 * @create 2021-03-05 15:40
 * @email:1057202547@qq.com
 * @dec: set 数组去重
 */
public class ArrdeweightTest {
    //练习：在List内去除重复数字值，要求尽量简单
    public static List duplicateList(List list) {
        HashSet set = new HashSet();
        set.addAll(list);
        return new ArrayList(set);
    }
    @Test
    public  void test1(){
        List list = new ArrayList();
        list.add(new Integer(1));
        list.add(new Integer(2));
        list.add(new Integer(2));
        list.add(new Integer(4));
        list.add(new Integer(4));
        List newArr = duplicateList(list);
        System.out.println(newArr.toString()); //[1, 2, 4]
    }

}
